#include "PauseState.h"
#include "GameObjectSystem.h"
#include "KeyboardInputManager.h"
#include "glog/logging.h"
#include "physicsComponent.h"
#include "PositionControllerComponent.h"
#include "gfxText.h"

PauseState::PauseState(const ObjectId& stateId)
	:FSMState(stateId)
	,m_uiTitle(NULL)
	,m_uiInfo(NULL)
{
	GameObjectSystem& gameObjectSystem = GameObjectSystem::GetSingleton();

	// Get the text properties.
	ObjectProperty* titleProperty = gameObjectSystem.editProperty(GfxText::GFX_TEXT_ID, "title1");
	if (titleProperty != NULL)
	{
		m_uiTitle = static_cast<GfxText*>(titleProperty);
	}
	DLOG_ASSERT(m_uiTitle);

	ObjectProperty* infoProperty = gameObjectSystem.editProperty(GfxText::GFX_TEXT_ID, "info1");
	if (infoProperty != NULL)
	{
		m_uiInfo = static_cast<GfxText*>(infoProperty);
	}
	DLOG_ASSERT(m_uiInfo);
}

void PauseState::onEnter()
{
	// Set texts.
	m_uiTitle->setText("* GAME PAUSED *");
	m_uiTitle->setFontColor(GfxColor::WHITE);
	m_uiTitle->setActive(true);

	m_uiInfo->setText("Press 'I' to continue.");
	m_uiInfo->setFontColor(GfxColor::WHITE);
	m_uiInfo->setActive(true);

	// Disable components (physics and input).
	GameObjectSystem& gameObjectSystem = GameObjectSystem::GetSingleton();

	Component* physicsComponent = gameObjectSystem.editComponent(PhysicsComponent::PHYSICS_COMPONENT_ID);
	physicsComponent->setActiveStatus(false);

	Component* positionControllerComponent = gameObjectSystem.editComponent(PositionControllerComponent::POSITION_CONTROLLER_ID);
	positionControllerComponent->setActiveStatus(false);
}

void PauseState::onLeave()
{
	// Disable texts.
	m_uiTitle->setActive(false);
	m_uiInfo->setActive(false);

	// Enable components (physics and input).
	GameObjectSystem& gameObjectSystem = GameObjectSystem::GetSingleton();

	Component* physicsComponent = gameObjectSystem.editComponent(PhysicsComponent::PHYSICS_COMPONENT_ID);
	physicsComponent->setActiveStatus(true);

	Component* positionControllerComponent = gameObjectSystem.editComponent(PositionControllerComponent::POSITION_CONTROLLER_ID);
	positionControllerComponent->setActiveStatus(true);
}
